package tree.traverse;

/**
 * @ author : HyoJoo-W
 * @ createDate : 2021-06-04 16:35
 * @ Description :
 */
public class BinaryTree
{
    private TreeNode root;

    public void setRoot(TreeNode root)
    {
        this.root = root;
    }

    //前序遍历
    public void preOrder()
    {
        if (this.root != null)
        {
            this.root.preOrder();
        }
        else
        {
            System.out.println("根节点为空");
        }
    }

    public void midOrder()
    {
        if (root != null)
        {
            root.midOrder();
        }
        else
        {
            System.out.println("根节点为空");
        }
    }

    public void postOrder()
    {
        if (root != null)
        {
            root.postOrder();
        }
        else
        {
            System.out.println("根节点为空");
        }
    }

    public TreeNode preOrderSearch(int findNo)
    {
        if (root != null)
        {
            return root.preOrderSearch(findNo);
        }
        else
        {
            return null;
        }
    }

    public TreeNode midOrderSearch(int findNo)
    {
        if (root != null)
        {
            return root.midOrderSearch(findNo);
        }
        else
        {
            return null;
        }
    }

    public TreeNode postOrderSearch(int findNo)
    {
        if (root != null)
        {
            return root.postOrderSearch(findNo);
        }
        else
        {
            return null;
        }
    }
}
